<template>
  <div class="custom-body" :style="borderStyle">
    <el-empty v-if="dataList === null || dataList.length === 0" :image-size="100" />
    <el-carousel v-else height="100%" class="custom-carousel">
      <el-carousel-item v-for="item in dataList" :key="'carousel-'+item.number">
        <carousel-item :number="item.number" />
      </el-carousel-item>
    </el-carousel>
  </div>
</template>

<script>
import CarouselItem from './slot/item'
export default {
  name: 'PcCarouselTempV1',
  components: { CarouselItem },
  props: {
    temp: {
      type: Object,
      default() {
        return {}
      }
    },
    showHeader: {
      type: Boolean,
      default: true
    }
  },
  data() {
    return {
      setting: null,
      dataList: []
    }
  },
  computed: {
    borderStyle() {
      if (this.temp.sfdzqp === true) {
        return { position: 'absolute', left: '0px', right: '0px', top: '0px', bottom: '0px' }
      }
      return { height: this.temp.defaultHeight }
    },
    headerStyle() {
      if (this.temp.sfzdy === true) {
        return { backgroundColor: this.temp.backgroundColor, color: this.temp.fontColor }
      }
      return {}
    }
  },
  watch: {
    temp: {
      handler(newData, oldData) {
        if (this.showHeader === true) {
          const pzx = JSON.parse(newData.data.pzx)
          this.setting = pzx
        } else {
          const pzx = JSON.parse(newData.pzx)
          this.setting = pzx
        }
        if (undefined !== this.setting.data) {
          this.dataList = this.setting.data
        } else {
          this.dataList = []
        }
      },
      immediate: true, // 父组件第一次传值时，执行handler，false则第一次不执行
      deep: false // formType为对象时，设置为true，此属性监听对象发生变化
    }
  }
}
</script>

<style scoped>
.custom-body {
  width: 100%;
  height: 100%;
  position: relative;
  background-color: #ffffff;
}
.custom-carousel {
  height: 100% !important;
}
</style>
